/**
 * 
 */
package cn.buk.tms.eotms.dao;

import cn.buk.tms.eotms.entity.Customer;
import java.util.List;
import jakarta.transaction.Transactional;
import org.springframework.stereotype.Component;

/**
 * @author yfdai
 *
 */
@Component
@Transactional
public class CustomerDaoImpl extends AbstractDao implements CustomerDao {

  @Override
  public Customer getCustomerByCustomerEnterpriseId(final int ownerId,
      final int customerEnterpriseId) {
    String hql = "select o from Customer o where o.enterpriseId = :ownerId and o.customerEnterpriseId = :customerEnterpriseId";
    List<Customer> customers = em.createQuery(hql, Customer.class)
        .setParameter("ownerId", ownerId)
        .setParameter("customerEnterpriseId", customerEnterpriseId)
        .getResultList();

    return customers.size() == 1 ? customers.get(0) : null;
  }

  @Override
  public Customer getCustomerById(int id) {
    return em.find(Customer.class, id);
  }

  @Override
  public List<String> getCustomerDepartmentOperator(int ownerId, int customerId, int deptId) {
    return doGetCustomerDepartmentOperator(ownerId, customerId, deptId);
  }
}
